#ifndef ESP01S_MQTT_WEB_MQTTCLIENT_H
#define ESP01S_MQTT_WEB_MQTTCLIENT_H
#include "config/GlobalConfig.h"

class MqttClient {
public:
    explicit MqttClient(GlobalConfig& config);
    bool connect();
    void loop();
        // 添加 tryReconnect 函数的声明
    [[nodiscard]] bool tryReconnect();
    GlobalConfig& config;
//    BearSSL::WiFiClientSecure espClient;
//    PubSubClient pubSubClient;
    void callback(char* topic, byte* payload, unsigned int length) const;
    void subscribeToTopics();
    void init();
    void setCallback();
private:
    static const char* getStateText(int state);
    static const int MAX_RECONNECT_ATTEMPTS = 5;
        // 定义定时器相关变量
    unsigned long lastLoopTime;
    const unsigned long loopInterval = 3000; // 每 10000 毫秒调用一次
};

#endif